#include "processbar.h"
#include <string.h>
#include <unistd.h>

const char  *lable = "|/-\\";

void version1()
{
    char buffer[NUM];
    int cur = 0;

    int n = strlen(lable);
    memset(buffer,'\0',sizeof(buffer));
    buffer[0] = HEAD;

    while (cur <= 100)
    {
        printf("[%-100s][%3d%%][%c]\r",buffer,cur,lable[cur%n]);
        buffer[cur++] = BODY;
        if (cur < 100) buffer[cur] = HEAD;

        fflush(stdout);
        usleep(50000);
    }
    printf("\n");
}

char buffer[NUM] = {0};
void version2(double rate)
{
    int cur = (int)rate;
    int n = strlen(lable);
    
    if (rate <= 1.0)buffer[0] = HEAD;

    //printf("[%-100s][%.1f%%][%c]\r",buffer,rate,lable[cur%n]);
    
    printf("[\033[31m%-100s\033[0m][%.1f%%][%c]\r",buffer,rate,lable[cur%n]);
    buffer[cur++] = BODY;
    if (cur < 100) buffer[cur] = HEAD;

    fflush(stdout);
}
//
//#define LAB ' '
//char buffer[NUM] = {0};
//
//
//void version2(double rate)
//{
//    int cur = (int)rate;
//
//    int n = strlen(lable);
//    
//    printf("[\033[41m\033[1m%s\033[0m][%.1f%%][%c]\r",buffer,rate,lable[cur%n]);
//    //buffer[cur++] = LAB;
//    //if (cur < 100) buffer[cur] = HEAD;
//
//    buffer[cur] = ' ';
//    fflush(stdout);
//}
